<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>列表动画</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <style>
        span{
            display: inline-block;
            margin: 0 10px;
            
        }
        .v-enter,.v-leave-to{
            transform :translateY(20px);
            opacity:0;
        }
        .v-enter-active,.v-leave-active{
            transition: all 2s;
        }
    </style>
</head>

<body>
    <div id="app">
       <button @click="add">add</button>
       <button @click="remove">remove</button>
       <transition-group tag="div">
            <span v-for="item in list" :key="item">{{item}}</span>
       </transition-group>
    </div>
    <script>
        var app = new Vue({
            el: "#app",
            data: {
                list:[1,2,3,4,5,6],
                nextNum:7,
            },
            methods: {
                randomIndex:function(){
                    return Math.floor(Math.random()*this.list.length);
                },
                add(){
                    this.list.splice(this.randomIndex(),0,this.nextNum++);
                },
                remove(){
                    this.list.splice(this.randomIndex(),1);
                }
            },

        })
    </script>
</body>

</html>